"""author:qinyu
   data: 2021/12/10
   project: cjh
"""
#1.使用类实现迭代器，实现斐波拉契数列
# class Fib():
#     def __init__(self,n):
#         self.i = 0
#         self.j = 1
#         self.n = n
#     def __iter__(self):
#         return self
#     def __next__(self):
#         self.i,self.j = self.j,self.i+self.j
#         if self.i < self.n:
#             return self.i
#         else:
#             raise StopIteration
#
# for a in Fib(100):
#     print(a, end=" ")






#2.使用面向对象做一个ATM（存取款功能）
#ATM类
#  属性： 钱，区域
#  方法：（存取）
#      用户可以过来取钱
#      取了钱ATM的钱就会减少
#      用户的账户的钱也会减少
#用户类
#  属性：用户名，  密码， 账户金额
#要求：
#    菜单   有登陆验证

class ATM():
    count_money = 100000
    area = '长沙'

    def draw_money(self, getmoney):
        self.money = self.money
        if getmoney <= self.money:
            self.money -= getmoney
            ATM.count_money -= getmoney
            print(f"业务交易成功，您的账户余额：{self.money},三乐银行总余额为：{self.count_money}")
        else:
            print("用户余额不足，请重新选择您想进行的业务!")


    def save_money(self, putmoney):
        ATM.count_money += putmoney
        self.money += putmoney
        print(f"业务交易成功，您的账户余额：{self.money},三乐银行总余额为：{self.count_money}")


class USER(ATM):
    dict = {"root": "123456","admin": "admin"}
    money = 5000

    def manu(self):
        print("欢迎使用三乐银行".center(30, "*"))
        print(f"{self.name}您的账户余额为：{self.money},三乐银行总余额：{self.count_money}")
        print("1.取钱    ".center(30, " "))
        print("2.存钱    ".center(30, " "))
        print("3.退出    ".center(30, " "))

    def register(self, name, passwd):
        if name in self.dict:
            print(f"{name}用户已存在，请重新注册")
        else:
            self.dict[name] = passwd
            # USER.__init__(self)
            ATM.count_money += self.money
            print("注册成功！")
            # print(self.dict)

    def login(self,name, passwd):
        if name in self.dict and passwd == self.dict[name]:
            self.name = name
            self.passwd = passwd
            print("用户登陆成功！")
            while 1:
                USER.manu(self)
                option = input("请输入你想进行的业务：")
                if option == "1":
                    get = int(input("请输入您想取出的金额："))
                    ATM.draw_money(self, get)
                elif option == "2":
                    put = int(input("请输入您想存入的金额："))
                    ATM.save_money(self, put)
                elif option == "3":
                    break
                else:
                    print("输入错误，请重新输入")
        else:
            print("账户密码验证错误，请重新确认登陆")

print(f"欢迎进入三乐银行".center(30, "*"))
while True:
    print(f"1.登陆".center(30, " "))
    print(f"2.注册".center(30, " "))
    option = input("请输入你的选择：")
    if option == "1":
        username = input("请输入用户名：")
        userpasswd = input("请输入密码：")
        USER.login(USER, username, userpasswd)
    elif option == "2":
        username = input("请输入用户名：")
        userpasswd = input("请输入密码：")
        # print(username,userpasswd)
        USER.register(USER, username, userpasswd)

    else:
        print("输入错误，请重新输入")